<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Unit_organisasi_model extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
	}

	public function get_unor( $parent  = '' )
	{
		$this->db->select('id,nama_unor,eselon_id,cepat_kode,nama_jabatan,diatasan_id,no_id');
		$this->db->where('diatasan_id',$parent);
		$this->db->order_by('no_id','ASC');
		$result = $this->db->get('sp_unor');
		
		$r = array();
		if($result->num_rows() > 0)
		{
			foreach($result->result() as $row)
			{
				$data['id'] = $row->id;
				$data['text'] = $row->nama_unor;
				$data['eselon_id'] = $row->eselon_id;
				$data['cepat_kode'] = $row->cepat_kode;
				$data['nama_jabatan'] = $row->nama_jabatan;
				$data['parent_id'] = $row->diatasan_id;
				$data['children'] = $this->get_unor( $row->id );
				$data['url'] = site_url("penunjang/unit_organisasi/edit/{$row->id}/{$row->no_id}");
				$r[] = $data;
			}
		}
		return $r;
	}

	public function get_unor_by_id( $id )
	{
		$this->db->where('diatasan_id',$id);
		$result = $this->db->get('sp_unor');
		return $result;
	}	
}